package com.itlong.cloud.sdk.resource;

import com.itlong.cloud.POJO.DTO.sdk.SDKAuthUserGetPageDTO;
import com.itlong.cloud.POJO.DTO.sdk.SDKSaveAppUserDTO;
import com.itlong.cloud.POJO.PO.*;
import com.itlong.cloud.POJO.VO.sdk.DeveloperAuthSafeSettingsVO;
import com.itlong.cloud.POJO.VO.sdk.SDKServerAppUserSaveVO;
import com.itlong.cloud.POJO.VO.sdk.SDKServerUserCacheVO;
import com.itlong.cloud.sdk.service.ISDKServerOldUserService;
import com.itlong.cloud.user.sdk.ISDKServerOldUserServiceClient;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      SDK人员信息业务处理暴露接口实现类
 * </desc>
 *
 * @createDate 2017/10/27
 */
@RestController
public class SDKServerOldUserServiceResource implements ISDKServerOldUserServiceClient {

    @Autowired
    ISDKServerOldUserService iSDKUserService;


    /**
     * <desc>
     *      SDK校验登录用户
     * <desc/>
     * @param   appid    独立开发者userId
     * @param  token       登录令牌
     *@return    SDKServerUserCacheVO   校验人员返回VO
     * @author Biao.R
     * @createDate 2017/10/27
     */
    @PostMapping(path = "/sdkServer/user/checkSDKCacheUser")
    @Override
    public SDKServerUserCacheVO checkSDKCacheUser(@RequestParam("appid") String appid, @RequestParam("token") String token) {
        return iSDKUserService.checkSDKCacheUser(appid,token);
    }


    /**
     * <desc>
     *      查询PropertyRoleProjectPO
     * <desc/>
     * @param  roleProjectPO 查询条件对象
     * @return  List<PropertyRoleProjectPO>  查询的对象结果集
     * @author Biao.R
     * @createDate 2017/11/3
     */
    @PostMapping(path = "/sdkServer/user/getRoleProject")
    @Override
    public List<PropertyRoleProjectPO> getRoleProject(@RequestBody PropertyRoleProjectPO roleProjectPO) {
        return iSDKUserService.getRoleProject(roleProjectPO);
    }

    /**
     * <desc>
     *      SDK服务端登录
     * <desc/>
     * @param appid     应用接入凭证
     * @param appsecret 应用接入密钥
     * @return  缓存对象
     * @author Biao.R
     * @createDate 2017/11/9
     */
    @PostMapping(path = "/sdkServer/user/sdkServerLogin")
    @Override
    public SDKServerUserCacheVO sdkServerLogin(@RequestParam("appid") String appid, @RequestParam("appsecret") String appsecret) {
        return iSDKUserService.sdkServerLogin(appid,appsecret);
    }

    /**
     * <desc>
     *      添加业主或者家人
     * <desc/>
     * @param   sdkSaveAppUserDTO  被授权的对象
     * @return  返回的用户及其房间信息
     * @author Biao.R
     * @createDate 2017/11/16
     */
    @PostMapping(path = "/sdkServer/user/addHouserOrFamily")
    @Override
    public SDKServerAppUserSaveVO addHouserOrFamily(@RequestBody SDKSaveAppUserDTO sdkSaveAppUserDTO) {
        return iSDKUserService.addHouserOrFamily(sdkSaveAppUserDTO);
    }

    /**
     * <desc>
     *      根据参数查询用户房间关联表
     * <desc/>
     * @param   params  查询参数
     * @return  List<AppUserRoomPO>    查询出的用户房间结果集
     * @author Biao.R
     * @createDate 2017/11/21
     */
    @PostMapping(path = "/sdkServer/user/getUserRoomByParam")
    @Override
    public List<AppUserRoomPO> getUserRoomByParam(@RequestBody Map<String, Object> params) {
        return iSDKUserService.getUserRoomByParam(params);
    }

    /**
     * <desc>
     *      根据参数查询授权关系表
     * <desc/>
     * @param   paramMap    查询参数集
     * @return  查询到的授权关系对象集
     * @author Biao.R
     * @createDate 2017/11/21
     */
    @PostMapping(path = "/sdkServer/user/getAuthRelationsByParams")
    @Override
    public List<AppAuthRelationsPO> getAuthRelationsByParams(@RequestBody Map<String, Object> paramMap) {
        return iSDKUserService.getAuthRelationsByParams(paramMap);
    }

    /**
     * <desc>
     *      根据手机号查询APP用户
     * <desc/>
     * @param   phoneNum     待查询的手机号
     * @return  查询到的用户信息
     * @author Biao.R
     * @createDate 2017/11/22
     */
    @PostMapping(path = "/sdkServer/user/getAppUserByPhone")
    @Override
    public AppUserInfoPO getAppUserByPhone(@RequestParam("phoneNum") String phoneNum) {
        return iSDKUserService.getAppUserByPhone(phoneNum);
    }

    /**
     * <desc>
     *      分页查询被授权人列表
     * <desc/>
     * @param  sdkAuthUserGetPageDTO    查询参数对象
     * @return  返回分页对象结果
     * @author Biao.R
     * @createDate 2017/11/22
     */
    @PostMapping(path = "/sdkServer/user/getAuthRelationsPage")
    @Override
    public Page<AppAuthRelationsPO> getAuthRelationsPage(@RequestBody SDKAuthUserGetPageDTO sdkAuthUserGetPageDTO) {
        return iSDKUserService.getAuthRelationsPage(sdkAuthUserGetPageDTO);
    }

    /**
     * <desc>
     *      根据userId查询AppUser
     * <desc/>
     * @param   userId  待查询的userId
     * @return  查询出的appUser对象
     * @author Biao.R
     * @createDate 2017/11/22
     */
    @PostMapping(path = "/sdkServer/user/getAppUserByUserId")
    @Override
    public AppUserInfoPO getAppUserByUserId(@RequestParam("userId") String userId) {
        return iSDKUserService.getAppUserByUserId(userId);
    }

    /**
     * <desc>
     *      更新授权关系表
     * <desc/>
     * @param   authRelationsPO     待更新对象
     * @return  更新数量
     * @author Biao.R
     * @createDate 2017/11/23
     */
    @PostMapping(path = "/sdkServer/user/updateAuthRelations")
    @Override
    public Integer updateAuthRelations(@RequestBody AppAuthRelationsPO authRelationsPO) {
        return iSDKUserService.updateAuthRelations(authRelationsPO);
    }

    /**
     * <desc>
     *      批量添加App用户
     * <desc/>
     * @param   saveAppUserDTOs     批量添加用户
     * @return  返回添加的数量Map
     * @author Biao.R
     * @createDate 2017/11/23
     */
    @PostMapping(path = "/sdkServer/user/addAppUsers")
    @Override
    public Map<String, Object> addAppUsers(@RequestBody List<SDKSaveAppUserDTO> saveAppUserDTOs) {
        return iSDKUserService.addAppUsers(saveAppUserDTOs);
    }

    /**
     * <desc>
     *      获取物业用户信息，条件：userId
     * </desc>
     *
     * @param appid 即userId
     * @return 物业用户信息
     * @author wangzhi
     * @createDate 2018/12/19
     */
    @Override
    @PostMapping(path = "/sdkServer/user/getPropertyUserByAppId")
    public PropertyUserInfoPO getPropertyUserByAppId(@RequestParam(value = "appid",required = false) String appid) throws Exception {
        return iSDKUserService.getPropertyUserByAppId(appid);
    }
    /**
     * <desc>
     *      获取开发者授权安全设置信息，条件：userId
     * </desc>
     *
     * @param appid 即userId
     * @return 开发者授权安全设置VO
     * @author wangzhi
     * @createDate 2018/12/19
     */
    @Override
    @PostMapping(path = "/sdkServer/user/getSafeSettings")
    public DeveloperAuthSafeSettingsVO getSafeSettings(@RequestParam("appid") String appid) throws Exception {
        return iSDKUserService.getSafeSettings(appid);
    }

    /**
     * <desc>
     *      获取物业用户信息，条件：userId
     * </desc>
     *
     * @param appid 即userId
     * @return 物业用户信息
     * @author wangzhi
     * @createDate 2018/12/19
     */
    @Override
    @PostMapping(path = "/sdkServer/user/getPropertyUserByUserName")
    public PropertyUserInfoPO getPropertyUserByUserName(@RequestParam(value = "appid",required = false) String appid) throws Exception {
        return iSDKUserService.getPropertyUserByUserName(appid);
    }
    /**
     * <desc>
     * 获取机器人编号
     * </desc>
     *
     * @param appid 即userName
     * @return 机器人编号
     * @author maju
     * @createDate 2021/05/26
     */
    @Override
    public String getRobotDevelopRobotInfo(String appid) throws Exception {
        return iSDKUserService.getRobotDevelopRobotInfo(appid);
    }

}